from visual import *

e = 1.602e-19
Ke = 9e9
electron = sphere(pos=(2,0,0), color=color.blue)
electron.vel = vector(0,0,0)
electron.charge = -1*e
electron.mass = 9.10938e-31
proton = sphere(pos=(-3,0,0), color=color.yellow)
proton.vel = vector(0,0,0)
proton.charge = e
proton.mass = 1.6726e-27
print(Ke, electron.charge, proton.charge, R)
dt = 0.01
while 1:
    rate(100)
    electron.pos = electron.pos + electron.vel*dt
    proton.pos = proton.pos + proton.vel*dt
    R = abs(proton.x**2 - electron.x**2)
    Coulomb = Ke*(electron.charge*proton.charge)/(R*R)
    print(Coulomb, R)
    if electron.x > 0:
        electron.vel.x = electron.vel.x + (Coulomb/electron.mass)*dt
        proton.vel.x = proton.vel.x - (Coulomb/proton.mass)*dt
    if electron.x < 0:
        electron.vel.x = electron.vel.x - (Coulomb/electron.mass)*dt
        proton.vel.x = proton.vel.x + (Coulomb/proton.mass)*dt
    else:
        electron.vel.x = electron.vel.x
        proton.vel.x = proton.vel.x
